<template>
	<view class="changePwd">
		<view class="item">
			<text>请输入当前登录密码</text>
			<el-input v-model="input1" placeholder="请输入当前登录密码"></el-input>
		</view>
		<view class="item">
			<text>确认新密码</text>
			<el-input v-model="input2" placeholder="确认新密码"></el-input>
		</view>
		<!-- 提示 -->
		<text class="tishi">必须是6-20个英文字母、数组或符号(除空格)，且字母、数字和标点符号至少包含两种</text>
		<!-- 按钮 -->
		<view style="width: 100%; display: flex;">
			<!-- pages/person/setUp/securityChild/complete -->
			<el-button type="primary" class='btn' @click="router('/pages/person/setUp/securityChild/complete')">确认
			</el-button>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				input1: '',
				input2: '',
				userPsd: '',
				user: {
					id: 0,
					username: '',
					password: ''
				}
			};
		},
		onShow() {
			const id = getApp().globalData.userId
			const username = getApp().globalData.username
			this.user.id = id
			this.user.username = username
			this.$api.searchUser({
				username
			}).then(res => {
				if (res.code == 200) {
					this.userPsd = res.data[0].password
					// console.log(this.userPsd)
				}
			})
		},
		methods: {
			router(path) {
				if (this.input1 !== '' && this.input2 !== '') {
					if (this.input1 === this.userPsd) {
						if (this.input2 !== '') {
							if (this.input2 !== this.input1) {
								this.user.password = this.input2
								this.$api.gutRegister(this.user).then(res => {
									console.log(res)
									if (res.code == 200) {
										localStorage.removeItem('token')
										getApp().globalData.userId = 0
										getApp().globalData.username = ''
										uni.navigateTo({
											url: '/pages/login/login'
										})
									}
								})
							} else {
								uni.showToast({
									title: '修改密码不能和当前密码一致',
									duration: 2000
								});
								return
							}
						} else {
							uni.showToast({
								title: '修改密码不能为空',
								duration: 2000
							});
							return
						}
					} else {
						uni.showToast({
							title: '当前登录密码错误',
							duration: 2000
						});
						return
					}
				} else {
					uni.showToast({
						title: '请您认真填写',
						duration: 2000
					});
					return
				}
			},
		}
	}
</script>

<style lang="scss">
	/deep/ .el-input {
		width: 60%;
	}

	/deep/ .el-input__inner {
		border: none;
	}

	.changePwd {
		width: 100vw;
		height: calc(100vh - 88upx);
		background: rgb(242, 243, 247);
		overflow: hidden;

		.item {
			margin: 30upx 0;
			box-sizing: border-box;
			padding: 10upx 30upx;
			background-color: white;
			font-weight: bold;
			font-size: 20upx;
			display: flex;
			align-items: center;
			justify-content: space-between;
		}

		.item:first-child {
			margin-top: 0;
		}

		.tishi {
			display: block;
			padding: 20upx 36upx;
			font-size: 26upx;
			color: rgb(153, 153, 153);
		}

		.btn {
			width: 90%;
			background: rgb(39, 209, 213);
			border: none;
			margin: 0 auto;
		}
	}
</style>
